package com.jxdinfo.hussar.activitidemo.utils;

import java.util.Calendar;

public class IdNo {
    public String idNo(String no,String id) {
        Calendar calendar = Calendar.getInstance();
        int yer = calendar.get(Calendar.YEAR);
        String year = "" + yer;
        String idNo;

        // 单号为空
        if (id == null || id.equals("")) {
            idNo=no+year+"0000";
        } else {
            String _year=id.substring(2,6);
            if (Integer.parseInt(_year)!=yer){
                idNo=no+year+"0000";
            }else {
                String fId = id.substring(6,id.length());
                int lsId = Integer.parseInt(fId) + 1;
                String strId = Integer.toString(lsId);
                if (strId.length()==1){
                    for (int i = 0; i <= 5 - strId.length(); i++) {//补零
                        strId = "0" + strId;
                    }
                }else {
                    if (strId.length()>1&&strId.length()<4){
                        for (int i = 0; i <= 4 - strId.length(); i++) {//补零
                            strId = "0" + strId;
                        }
                    }
                }
                idNo=no+year+strId;
            }

        }
        return idNo;
    }
    public String idNo2012(String no,String id,String yer) {

        String idNo;

        // 单号为空
        if (id == null || id.equals("")) {
            idNo=no+yer+"0000";
        } else {
            String fId = id.substring(6,id.length());
            int lsId = Integer.parseInt(fId) + 1;
            String strId = Integer.toString(lsId);
            if (strId.length()==1){
                for (int i = 0; i <= 5 - strId.length(); i++) {//补零
                    strId = "0" + strId;
                }
            }else {
                if (strId.length()>1&&strId.length()<4){
                    for (int i = 0; i <= 4 - strId.length(); i++) {//补零
                        strId = "0" + strId;
                    }
                }
            }
            idNo=no+yer+strId;
        }


        return idNo;
    }
}
